import os
import re
R_5name=[]
R_10name=[]

G_5name=[]
G_10name=[]

B_5name=[]
B_10name=[]

R_Ref_name=[]
G_Ref_name=[]
B_Ref_name=[]


def extract_fime_name():
    pattern_R_5 = "(?=.*R)(?=.*5)"
    pattern_R_10 = "(?=.*R)(?=.*10)"
    pattern_R_Ref = "(?=.*[0-9]_R)(?=.*Ref)"

    pattern_G_5 = "(?=.*G)(?=.*5)"
    pattern_G_10 = "(?=.*G)(?=.*10)"
    pattern_G_Ref = "(?=.*G)(?=.*Ref)"

    pattern_B_5 = "(?=.*B)(?=.*5)"
    pattern_B_10 = "(?=.*B)(?=.*10)"
    pattern_B_Ref = "(?=.*B)(?=.*Ref)"


    target_folder = '.\\Data_process\\Raw_data'
    output_file_name = 'extra_file_name.txt'
    finally_name=''
    if os.path.exists(target_folder):
        for file_name in os.listdir(target_folder):
            if re.search(pattern_G_5,file_name):
                G_5name.append(file_name)
            if re.search(pattern_G_10,file_name):
                G_10name.append(file_name)
            if re.search(pattern_G_Ref,file_name):
                G_Ref_name.append(file_name)
            
            if re.search(pattern_R_5,file_name):
                R_5name.append(file_name)
            if re.search(pattern_R_10,file_name):
                R_10name.append(file_name)
            if re.search(pattern_R_Ref,file_name):
                R_Ref_name.append(file_name)

            if re.search(pattern_B_5,file_name):
                B_5name.append(file_name)
            if re.search(pattern_B_10,file_name):
                B_10name.append(file_name)
            if re.search(pattern_B_Ref,file_name):
                B_Ref_name.append(file_name)


        R_5name_str=str(R_5name).replace("'","")
        R_5name_str = re.sub(r",\s+", ",", R_5name_str)

        R_10name_str=str(R_10name).replace("'","")
        R_10name_str = re.sub(r",\s+", ",", R_10name_str)

        R_Ref_name_str=str(R_Ref_name).replace("'","")
        R_Ref_name_str = re.sub(r",\s+", ",", R_Ref_name_str)


        G_5name_str=str(G_5name).replace("'","")
        G_5name_str = re.sub(r",\s+", ",", G_5name_str)
        # print(G_5name_str)

        G_10name_str=str(G_10name).replace("'","")
        G_10name_str = re.sub(r",\s+", ",", G_10name_str)

        G_Ref_name_str=str(G_Ref_name).replace("'","")
        G_Ref_name_str = re.sub(r",\s+", ",", G_Ref_name_str)



        B_5name_str=str(B_5name).replace("'","")
        B_5name_str = re.sub(r",\s+", ",", B_5name_str)

        B_10name_str=str(B_10name).replace("'","")
        B_10name_str = re.sub(r",\s+", ",", B_10name_str)

        B_Ref_name_str=str(B_Ref_name).replace("'","")
        B_Ref_name_str = re.sub(r",\s+", ",", B_Ref_name_str)




        finally_name=R_Ref_name_str+' '+G_Ref_name_str+' '+B_Ref_name_str+' '+R_5name_str+' '+R_10name_str+' '+G_5name_str+' '+G_10name_str+' '+B_5name_str +' '+B_10name_str
        
        finally_name_only_Ref=R_Ref_name_str+' '+G_Ref_name_str+' '+B_Ref_name_str
        # finally_name=R_Ref_name_str+' '+G_Ref_name_str+' '+R_5name_str+' '+R_10name_str+' '+G_5name_str+' '+G_10name_str

        with open(output_file_name,'w') as file:
            file.write(finally_name+'\n'+'\n')

            file.write(finally_name_only_Ref)
            print('需要输入的文件名，输出到根目录下的 extra_file_name.txt，启动小程序请复制粘贴使用')
        return finally_name,finally_name_only_Ref
    # print(f'一共迁移文件数量为：{count}')

            
# extract_fime_name()